Skip to main content

Script to ping multiple IP addresses and Host names using powershell

Lets in this tutorial I am going to share you the script through which you can ping multiple IP Addresses using Powershell and text file.


Here are the multiple question I received from my viewers & workmates & friends, these are:- 

Do I ping multiple IP addresses at once.
Is it really possible to ping multiple IP Address / Host names at once ?
How to ping multiple IP and make a output into text file?
Multiple host names / IP address ping & output automatically?
How to ping all IP addresses under my Lan connection. 
Powershell scripting for ping list of IP Address and output as text file?


Well, the answer of these question is "YES". You can easily ping all the IP addresses which you really want. But you need to read my content very carefully. 


Before jumping to main content, one request to all of you, if you really like my content, if my content really helpful for you then please visit my youtube channel "SVM VLOGS" & do subscribe my channel, your kind support is really important for me. So without wasting any more times, lets get started!!

Firstly you need make a list of IP addresses in a text file and saved it in your system hard drive. As you can see in the below images, in my case I have written few IP address in a text file with a name called "ip.txt" in a "Y drive" of my computer hard disk. 

Once you done with text file & IP addresses, now you need to open Windows Powershell ISE in your system. To open the application all you need to press [windows] button & in the search box just type "Powershell ISE" & hit Enter.  


Yessss! We can proceed further now.

 

Now, under Powershell ISE you need to copy paste the below lines, followed by press the Run Script button. But before hit the Run button paste my below codes:- 

 

$names=Get-Content "Y:\ip.txt"
foreach ($name in $names){
if(Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
Write-Host "$name is UP" -ForegroundColor Green
$Output+="$name is UP"+"`n"
}
else{
Write-Host "$name is DOWN" -ForegroundColor Red
$Output+="$name is DOWN"+"`n"
}
}
$Output | Out-File "Y:\pingtest.txt"
Start-Sleep -s 10 


So far so good!! Now lets check with the results / output.

As you can see here in left side, under powershell ISE application you can see the result of ping test of multiple IP, side by side on the other image you can see in my computer hard disk "Y" Drive one file will create namely "pingtest.txt" [you can change the output file name, by editing the scripting code.] under this pingtest.txt file the output will be generate of a IP ping test.

 You can save the script file in your system, through which you can easily run the ping test of the IP addresses with a single click. For this you need to save the script, and here is the steps you need to follow:-

Step 1: Right after copy & paste the code hit the "File" button followed by click on "Save as" button.

Step 2: Choose the destination where you want to save the script file, in my case I am going to save in my "Desktop" which is really convenient for all of us.

Step 3 : Give a filename, whatever you want and click on save button. 

Good news buddy!! You have created the script file for your future usage.  

Next time if you want to check ping status of IP Addresses / Host names you really do not need to copy paste my code. All you have to simply right click on the script file & choose "Run with Poweshell" option. 

With your single click the script start working on it & you'll get the output both in powershell and the text file.

Additional Tips : If you want to ping more IP Addresses / Host names simply edit your text files and it works like a charm. Hope this tutorial helps you with your query, if you have any doubts please comment down below, I'll try to answer you all. Don't forget to subscribe me on Youtube. Thanks for visiting my site, will see you soon in my next blog. 

Comments